//
//  FlipViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class FlipViewController: UIViewController {


    @IBOutlet var imageView_cat: UIImageView!
    

    @IBOutlet var imageView_dog: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "翻转", style: UIBarButtonItemStyle.Bordered, target: self, action: "flip")
        
        
    }
    
    
    func flip(){
        self.navigationItem.rightBarButtonItem = nil
        
        
        UIView.beginAnimations("flip", context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(1.0)
        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromLeft, forView: imageView_cat, cache: true)
        
        self.view.exchangeSubviewAtIndex(0, withSubviewAtIndex: 1)
        
        UIView.setAnimationDelegate(self)
        UIView.setAnimationDidStopSelector("animationFinished")
        UIView.commitAnimations()
        
    }
    
    func animationFinished(){
        println("------------")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "翻转", style: UIBarButtonItemStyle.Bordered, target: self, action: "flip")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
